package com.violet.base.server.dic.controller;

import com.violet.base.api.dic.condiftion.DictTypeCondition;
import com.violet.base.api.dic.dto.DicTypeDTO;
import com.violet.base.server.dic.service.DictTypeService;
import com.violet.common.page.PageParam;
import com.violet.common.page.PageResult;
import com.violet.common.page.SortParam;
import com.violet.common.response.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: wqf
 * @Date: 2022/10/27
 * @Description:
 */
@Tag(name = "字典分类模块", description = "字典分类模块")
@RestController
@RequestMapping("/dict/type")
public class DictTypeController {

    @Resource
    private DictTypeService dictTypeService;


    @Operation(summary = "分页查询字典类型")
    @GetMapping
    public Result<PageResult<DicTypeDTO>> listDictType(DictTypeCondition condition, PageParam pageParam, SortParam sortParam) {
        PageResult<DicTypeDTO> pageResult = dictTypeService.listDictType(condition, pageParam, sortParam);
        return Result.succeed(pageResult);
    }

    @Operation(summary = "新增字典类型")
    @PostMapping
    public Result<Void> addDictItem(DicTypeDTO dicTypeDTO) {
        dictTypeService.saveOrUpdateDictType(dicTypeDTO);
        return Result.succeed();
    }

    @Operation(summary = "更新字典类型")
    @PutMapping
    public Result<Void> updateDictType(DicTypeDTO dicTypeDTO) {
        dictTypeService.saveOrUpdateDictType(dicTypeDTO);
        return Result.succeed();
    }

    @Operation(summary = "删除字典类型")
    @DeleteMapping("/{id}")
    public Result<Void> deleteDictTypeById(@Parameter(description = "主键id") @PathVariable Long id) {
        dictTypeService.deleteDictTypeById(id);
        return Result.succeed();
    }
}
